/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
 */

package device

import (
	"encoding/base64"

	"errors"
)

type (
	SecKey     [32]byte
	NoiseNonce uint64 // padded to 12-bytes
)

func (key *SecKey) FromString(src string) error {
	slice, err := base64.StdEncoding.DecodeString(src)
	if err != nil {
		return err
	}
	if len(slice) != len(key) {
		return errors.New("base64 string does not fit the slice")
	}
	copy(key[:], slice)
	return nil
}
func (key *SecKey) to32() [32]byte {
	var dst [32]byte
	copy(dst[:], key[:])
	return dst
}
